<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function add(Request $request)
    {
        $this->validate($request,[
            'name'=>'required',
            'tel'=>'required',
            'email'=>'required',
            'pwd'=>'required',
            'qpwd'=>'required',
        ]);
        $data=User::Adds($request);
        if($data)
        {
            return redirect('user.login');
        }
        else{
            return redirect('user.add');
        }
    }
    public function login(Request $request)
    {
        $this->validate($request,[
            'name'=>'required',
            'pwd'=>'required',
        ]);
        $data=User::Login($request);
        if($data)
        {
            return redirect('show');
        }
        else{
            return redirect('login');
        }
    }
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function duan()
    {
        $rand=rand(10000,99999);
       $statusStr = array(
                "0" => "短信发送成功",
                "-1" => "参数不全",
                "-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
                "30" => "密码错误",
                "40" => "账号不存在",
                "41" => "余额不足",
                "42" => "帐户已过期",
                "43" => "IP地址限制",
                "50" => "内容含有敏感词"
                );
                $smsapi = "http://api.smsbao.com/";
                $user = "zjh120704"; //短信平台帐号
                $pass = md5("750719zxcv"); //短信平台密码
                $content="本次验证码是:".$rand;//要发送的短信内容
                $phone = "19974970012";//要发送短信的手机号码
                $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
                $result =file_get_contents($sendurl) ;
                echo $statusStr[$result];
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\User  $user
     * @return \Illuminate\Http\Response
     */
    public function show(User $user)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\User  $user
     * @return \Illuminate\Http\Response
     */
    public function edit(User $user)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\User  $user
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, User $user)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\User  $user
     * @return \Illuminate\Http\Response
     */
    public function destroy(User $user)
    {
        //
    }
}
